package logic

import (
	"context"
	"usersrv/user"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserRealnameRequestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserRealnameRequestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRealnameRequestLogic {
	return &UserRealnameRequestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserRealnameRequestLogic) UserRealnameRequest(req *types.UserRealnamerequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	realname, err := l.svcCtx.UserSrv.UserRealname(l.ctx, &user.UserRealnameRequest{
		UserId:   int64(req.UserId),
		Realname: req.Realname,
		Idcard:   req.Idcard,
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "实名认证成功",
		Code: 200,
		Data: realname,
	}, nil
}
